home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / gcl-1.000 / gcl-1 / gcl-1.0 / mp / mp_divul3_word.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-07  |  2.1 KB  |  78 lines

  1.  
  2. /*          Copyright (C) 1994 W. Schelter
  3.  
  4. This file is part of GNU Common Lisp, herein referred to as GCL
  5.  
  6. GCL is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GCL is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU library general public
  17. license along with GCL; see the file COPYING.  If not, write to the
  18. Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. typedef unsigned long ulong;
  22.  
  23. ulong
  24. divul3(x,y,hi)
  25.      ulong x,y,*hi;
  26. {
  27. #define HIBIT 0x80000000
  28. #define HIMASK 0xffff0000
  29. #define LOMASK 0xffff
  30. #define HIWORD(a) (a >> 16)
  31. /* si le compilateur est bugge, il faut mettre (a >> 16) & LOMASK) */
  32. #define LOWORD(a) (a & LOMASK)
  33. #define GLUE(hi, lo) ((hi << 16) + lo)
  34. #define SPLIT(a, b, c) b = HIWORD(a); c = LOWORD(a)
  35.  
  36.     ulong v1, v2, u3, u4, q1, q2, aux, aux1, aux2,hiremainder=*hi;
  37.     int k;
  38.     
  39.     for(k = 0; !(y & HIBIT); k++)
  40.         {
  41.             hiremainder <<= 1;
  42.             if (x & HIBIT) hiremainder++;
  43.             x <<= 1;
  44.             y <<= 1;
  45.         }
  46.         
  47.     SPLIT(y, v1, v2);
  48.     SPLIT(x, u3, u4);
  49.     
  50.     q1 = hiremainder / v1; if (q1 & HIMASK) q1 = LOMASK;
  51.     hiremainder -= q1 * v1;
  52.     aux = v2 * q1;
  53. again:
  54.     SPLIT(aux, aux1, aux2);
  55.     if (aux2 > u3) aux1++;
  56.     if (aux1 > hiremainder) {q1--; hiremainder += v1; aux -= v2; goto again;}
  57.     u3 -= aux2;
  58.     hiremainder -= aux1;
  59.     hiremainder <<= 16; hiremainder += u3 & LOMASK;
  60.     
  61.     q2 = hiremainder / v1; if (q2 & HIMASK) q2 = LOMASK;
  62.     hiremainder -= q2 * v1;
  63.     aux = v2 * q2;
  64. again2:
  65.     SPLIT(aux, aux1, aux2);
  66.     if (aux2 > u4) aux1++;
  67.     if (aux1 > hiremainder) {q2--; hiremainder += v1; aux -= v2; goto again2;}
  68.     u4 -= aux2;
  69.     hiremainder -= aux1;
  70.     hiremainder <<= 16; hiremainder += u4 & LOMASK;
  71.     hiremainder >>= k;
  72.     *hi = hiremainder;
  73.     return GLUE(q1, q2);
  74. }
  75.  
  76.  
  77.  
  78.